class Event < ActiveRecord::Base
  belongs_to :ecase
  belongs_to :slideshow
  has_many :slideshow_images, :through => :slideshow
  has_many :comments, :as => :commentable, :dependent => :destroy , :order => "created_at DESC" 
  has_many :last_comments ,:class_name => "Comment", :as => :commentable , :order => "created_at DESC" ,:limit =>20
  
  has_one :region, :dependent => :destroy
  validates_presence_of :date,:ecase_id,:title
  
  def get_type
    self.class.to_s.downcase
  end

  def get_controller
    "events"
  end

  def date_time
    DateTime.parse(@attributes['date'])
  end
  
  def date_formatted
    att = @attributes['date']
    "#{att[8,2]} #{Date::MONTHNAMES[att[5,2].to_i]} #{att[0,4]}" 
  end
  
  def author_id
    ecase.author_id 
  end
    
  def author
    ecase.author
  end
  
  def description_filled
    (description.nil? || description.size < 1) ? EMPTY_EDITOR_TEXT : description
  end 
end
